package com.huan.rss.reader;

import com.huan.rss.bean.CommonInformationItem;
import com.huan.rss.bean.RSSDataCapturer;
import com.huan.rss.buffer.NewBuffer;
import org.apache.log4j.Logger;

import java.util.List;

/**
 * 爬取新闻的任务
 */

public class NewsReaderTask implements Runnable{

    private Logger logger = Logger.getLogger(NewsReaderTask.class);
    private String name;
    private String url;
    private NewBuffer   buffer;

    public NewsReaderTask(String name, String url, NewBuffer buffer) {
        this.name = name;
        this.url = url;
        this.buffer = buffer;
    }
    @Override
    public void run() {
        RSSDataCapturer capturer = new RSSDataCapturer(name);
        List<CommonInformationItem> list = capturer.load(url);
        //将数据写入缓存
        for (CommonInformationItem item : list) {
            buffer.add(item);
        }
        logger.debug(name + "下载完毕");
    }
}
